exports.path = '/xxDealOrder/getBssTradeInfo';
exports.title = '获取工单信息';
// 本范例首先展示 select SQL query 场景

exports.sqltext = ({
  essOrderId, serialNumber,
}) => `select e.ess_order_id,
       a.trade_id,
       a.serial_number,
       (SELECT PSPT_TYPE
          FROM ucr_cen1.td_s_passporttype c
         WHERE sysdate BETWEEN c.start_date AND c.end_date
           and c.pspt_type_code = b.pspt_type_code) pspt_type_name,
       b.pspt_id,
       (select trade_type from ucr_cen1.td_s_tradetype d where d.trade_type_code =a.trade_type_code and d.net_type_code =a.net_type_code) trade_type_name,
       a.contact,
       a.contact_phone
  from ucr_crm1.tf_b_trade a, ucr_crm1.tf_f_customer b ,ucr_crm1.tf_b_trade_cbss e
 where a.trade_type_code = '10'
   and a.net_type_code = '44'
   and a.next_deal_tag = 'V'
   and a.cust_id = b.cust_id
   and a.trade_id =e.trade_id
   ${essOrderId ? 'and e.ess_order_id = :essOrderId' : ''}
   ${serialNumber ? 'and a.serial_number = :serialNumber' : ''}
`;

exports.pool = 'task';

// 请求范例，用于调用者了解请求数据结构，也用于系统自动内测发起请求
exports.examples = [{
  in: {
    essOrderId: '1314012300708189',
    // serialNumber: '02207039754',
  },
  out: {
    ESS_ORDER_ID: 1314012300708189,
    TRADE_ID: 4018061976681678,
    SERIAL_NUMBER: '02207039754',
    PSPT_TYPE_NAME: '身份证',
    PSPT_ID: '120106198102137524',
    TRADE_TYPE_NAME: '开户',
    CONTACT: "'丽丽'",
    CONTACT_PHONE: "'15122023009'",
  },
}];


exports.outConverter = (sqlResult, req) => {
  const result = sqlResult.rows[0];
  if (!result) throw new Error(`查无补拍工单 essOrderId:${req.essOrderId} serialNumber:${req.serialNumber || ''}`);
  return result;
};
